﻿using System;
using System.Collections.Generic;
using YJKRevitBase.Math;
using YJKRevitDimensionText.VerticalAutoDim.GeoModel;

namespace YJKRevitDimensionText.VerticalAutoDim.Comparer
{
	internal class GeoComparerAtEqualLevel : IComparer<IPlanarGeo>
	{
		public GeoComparerAtEqualLevel(bool bIsByLeft = true)
		{
			this.IsByLeft = bIsByLeft;
		}

		public int Compare(IPlanarGeo x, IPlanarGeo y)
		{
			if (this.IsByLeft)
			{
				return this.ByLeftComparer(x, y);
			}
			return this.ByRightComparer(x, y);
		}

		private int ByLeftComparer(IPlanarGeo x, IPlanarGeo y)
		{
			double num = x.Min2DPointECS.X - y.Min2DPointECS.X;
			if (MathUtility.IsEqual(num, 0.0))
			{
				return 0;
			}
			if (MathUtility.GreaterThan(num, 0.0))
			{
				return 1;
			}
			return -1;
		}

		private int ByRightComparer(IPlanarGeo x, IPlanarGeo y)
		{
			double num = x.Max2DPointECS.X - y.Max2DPointECS.X;
			if (MathUtility.IsEqual(num, 0.0))
			{
				return 0;
			}
			if (MathUtility.LessThan(num, 0.0))
			{
				return 1;
			}
			return -1;
		}

		protected readonly bool IsByLeft;
	}
}
